import { getListApi, addMsbdApi, deleteMsbdApi, updateMsbdApi } from '../../assets/audit/msbd'

export const state = () => {
    return {
        tableData: [],
        total: 0,
        currentPage: 1,
        pageSize: 3
    }
}

export const mutations = {
    SET_DATA(state, val) {
        state.tableData = val.data
        state.total = val.total
    },
    CURRENTPAGE(state, val) {
        state.currentPage = val
    },
    PAGESIZE(state, val) {
        state.pageSize = val
    }
}

export const actions = {
    async getList({ commit, state }, query) {
        const r = await getListApi({ currentPage: state.currentPage - 1, pageSize: state.pageSize, query })
        console.log(r)
        commit('SET_DATA', { data: r.data, total: r.total })
    },

    async addMsbd({ dispatch }, data) {
        await addMsbdApi(data)
        dispatch('getList')
    },

    async deleteMsbd({ dispatch }, data) {
        await deleteMsbdApi(data)
        dispatch('getList')
    },

    async updateMsbd({ dispatch }, data) {
        await updateMsbdApi(data)
        dispatch('getList')
    }
}
// export const getters = {}
